import { createStore } from "vuex"
import rosy from "./modules/Rosy"
import leo from "./modules/Leo"

export default createStore({
  state: {
    counter: 0,
    name: "Root",
  },
  mutations: {
    increment(state) {
      state.counter++
    },
    decrement(state) {
      state.counter--
    },
  },
  actions: {
    incrementAsyn({ commit }) {
      setTimeout(() => {
        commit("increment")
      }, 1000)
    },
    decrementAsyn({ commit }) {
      setTimeout(() => {
        commit("decrement")
      }, 1000)
    },
  },
  getters: {
    doubleCounter(state) {
      return state.counter * 2
    },
    //getters可以接受第二个参数
    calCounter(state, getters) {
      return state.counter + "加倍得：" + getters.doubleCounter
    },
  },
  modules: {
    rosy,
    leo,
  },
})
